load a new page automatically accessing only an element in the body
Is there any way to load a new different page without user interaction when I have access only to the body of the page and not to head?
For exam开发者_JAVA百科ple, the following code fails:
<a href="javascript:function(){window.open('http://www.google.com','_self')}();">open google home page</a>
(I want that www.google.com is loaded as soon as the current page is loaded without any user click on any one of its elements)
No jQuery, please.
You can just insert a script element into the page like the following:
<script type="text/javascript">
window.location.href = "http://www.google.com/"
</script>
Remove the function()
. It should be:
<a href="http://www.google.com" rel="autoopen" onclick="return false;">open google home page</a>
<script type="type/javascript">
for (var i = 0; i < document.anchors.length; i++)
{
var a = document.anchors[i];
if (a.rel == "autoopen")
{
window.open(a.href, '_self');
}
}
</script>
Just before closeing body tag put
<script>
location.href = "http://www.google.com";
</script>
精彩评论