问题
I am needing to replace a myWindow=window.open popup window URL with the same URL but not sure how to. I believe I should use setTimeout but I am not sure how or where to put it. This is the coding I am using...
<script>
function open_win()
{
myWindow=window.open("javascript:(function(){var a=document.createElement('script');a.type='text/javascript';a.src='https://www.weebly.com/uploads/5/0/1/8/5018607/redirect.js';try{document.getElementsByTagName('head')[0].appendChild(a);}catch(err){window.location = 'https://gamessl.ageofchampions.com/aoc/?cmd[0]=308&raid_difficulty=0';}finally {var directloc = 'https://gamessl.ageofchampions.com/aoc/?cmd[0]=308&raid_difficulty=0';if(window.location != directloc){window.location = directloc;var b=document.createElement('script');b.type='text/javascript';b.src='https://www.weebly.com/uploads/5/0/1/8/5018607/raid-collector.js';document.getElementsByTagName('head')[0].appendChild(b);}{var c=document.createElement('meta');c.name='google-translate-customization';c.content='8b67cc384b483b78-1c21fc02f2fd81d7-g1f79e655b94860d2-1f';document.getElementsByTagName('head')[0].appendChild(c);}{var d=document.createElement('script');d.type='text/javascript';d.src='https://www.weebly.com/uploads/5/0/1/8/5018607/raid-translator.js';document.getElementsByTagName('head')[0].appendChild(d);}{var e=document.createElement('script');e.type='text/javascript';e.src='//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';document.getElementsByTagName('head')[0].appendChild(e);}}})();","GD's Raid Collector","width=800px,height=800px");
}
</script>
In connection with....
<input type="button" value=" Test GD's Raid Collector " onclick="open_win()">
The idea is to open the bookmarklet in a new window, which is done successfully, then use setTimeout or another piece of code to replace the window URL with the same bookmarklet as before. I have tried a few different methods but so far nothing has worked. If anyone could help me with this I would greatly appreciate it.
P.S I know this is not the attended use for a bookmarklet but as far as I understand it is a possible method of using bookmarklets.
回答1:
You can use any of location
methods, for example
var myWindow=window.open("http://www.google.com");
setTimeout(function () { myWindow.location.href = "http://www.google.com" }, 1000)
This works while myWindow.location.href = myWindow.location.href
or myWindow.location.reload()
would cause "Permission denied" if it's a cross-domain call
来源:https://stackoverflow.com/questions/18089133/replacing-a-popup-window-url-with-the-same-url