Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a webpage and run some javascript functions?

Tags:

javascript

Hi I would like to open a page and then run some javascript functions. My problem is that once I open the window it stops running the code:

javascript:
location=("http://www.myTestPage.com/");
showForm();
document.getElementById("txtEmail").value="[email protected]";
submit();
like image 479
Deelo55 Avatar asked Dec 21 '25 14:12

Deelo55


2 Answers

You can't. The problem is that each page is loaded into its own logical window (even if that window occupies the same client area in the browser as the previous page). Each window runs script in its own context. Usually when windows are replaced any running script is terminated and even if it weren't I suspect you want the code following the location assignment to operate on the new content.

You would need the target page to run your code for you. If the page is generated dyanmically by something like PHP or ASP then you could use the query string to specify a file that the page should point the SRC of a script block it puts at the bottom of the body content.

like image 163
AnthonyWJones Avatar answered Dec 24 '25 02:12

AnthonyWJones


It's because your javascript functions are declared in the window object. By calling location= you destroy the current window object and all the function in it. After all you cant declare function in one window to run in the same same window but with another location. All you can do is toopen a new window.

like image 37
Andreas Köberle Avatar answered Dec 24 '25 02:12

Andreas Köberle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!