Run link after code execution JavaScript - javascript

I want to run psns: after my code has executed as a link. psns: will close the PlayStation 4 browser and is designed to be clicked on, but I want to automatically run it without having the user click on it.
This is what I have:
if(alert('The browser will now close.')) window.location.href='psns:';
I do get the alert, but for some odd reason the browser does not close, even though when you click a link with psns: as a href, it does. How can I make it so it runs psns: after the alert?

Related

How can I debug calls to window.open?

I have some React app here that has a malfunction that causes the page to open a new tab with itself. Recursive. and that is rather annoying as the number of tabs runs quickly into an out of memory situation. I want to debug the code to see the stack when the window.open call happens. I do not know where in the application the call happens and so wonder if there is a way to trigger Chrome to jump into script debug mode when something wants to open a window/tab?
So you can use the debugger of chrome, and then add some breakpoint to exactly decide when the code should stop, and then you use the control to jump to the next execution and decide when to go a step back and forth.
it's available for free, all you need to do is to inspect your React app and then visit the Sources tab, there you will see the code in javascript and you can start adding breakpoint and so.
You can also add mouse event listener , like click , dbclick...
You can also trigger and debug how a specific function si running.

Changes in code not taking effect - Visual web developer

I have a button which is calling a function that displays an alert. The alert is displayed but if I change the messege that the alert is showing, when I press the button the alert will still show the first message I wrote and not the updated one.
It is also happening when I add html tags, they won't show when I run the code.
Why is this happening?
You know the drill: make some edits to your document, click save, switch over to your browser, refresh it, and then observe the changes.
However, every now and again I will catch myself viewing the wrong site page, viewing the site on a different browser, or viewing the client's old live site! Check your address bar + go into your folder and open the page again.

Javascript breakpoint on user event

When I click a button in my app a series of Javascript code is executed, in this particular case, I click on a "Cancel" button to close the currently open modal window. This close button looks like this on HTML:
<a class="cancel close">Cancel</a>
What I need is a way to track what is "triggered" by the action of clicking this <a> element in Javascript, without having to look into .js files for a reference to this DOM element (where the event was binded to the <a> element).
Is there a way of creating some sort of breakpoint in Javascript after a user generates an event but I don't know where that Javascript code is? In order to actually find where that code is.
I'm using Google Chrome/Developer Tools for debugging Javascript.
Open the developer console; switch to the scripts tab; click in the left-hand margin (on the line number) to set a breakpoint. The script's execution will pause at the breakpoint, and you can inspect the call stack, local variables, and so on.
Or, you can click "Pause", before you trigger an event, and script execution will pause (like setting a global breakpoint) as soon as a script is about to execute, and show you the code. Then you can resume, step over, step into, or step out of the current function/expression.
You can do that in Firebug and the built-in consoles in Safari, Chrome, Opera and IE.
Edit: I should add, that the pause-button is less useful if you have javascript-driven animations, ajax polling, or other code being called with an interval, since the pause button stops any script execution until you click resume. So it'll pause when, say, an animation's update function is called, probably way before you have a chance to trigger the code you're interested it.
However, in there's also "Break on exceptions" and "Break on uncaught exceptions" option in most (if not all) developer consoles. Like the pause button, it's like having a global breakpoint, except it only stops when there's trouble. So if the code you're trying to find is causing errors or throwing exceptions, you can set the debugger to pause the script when that happens.
Firebug is an option for FF.
http://getfirebug.com/doc/breakpoints/demo.html

How to not wait for something with Watir-Webdriver

So I'm writing a watir-webdriver script, and my app is using javascript to present a modal window that I want to interact with. When I click the element that presents the modal window, watir-webdriver just sits there until eventually it times out and i see a Timeout::Error on the console window. This is before attempting to interact with the new window at all. I'm assuming it's polling the DOM for some change and not getting it, how do I tell it to move on without waiting?
The answer ended up being, and then handling the necessary waiting manually
element.focus
element.send_keys :return
Ruby 1.9.3/ IE 9 - I had a click_no_wait error. Watir would not trigger a click on the Save button, which had to be followed by a click on a java popup 'OK' button that confirmed that the save button had saved the document correctly.
Using these two lines in place of the click_no_wait command gets the code working perfectly:
element.focus
element.send_keys :return
Thanks DVG. My code -
ie.button(:id, 'MainContent_B_Save').focus
ie.button(:id, 'MainContent_B_Save').send_keys :return
ie. javascript_dialog.button('OK').click
If this is a Alert, Confirm, or Alert type JS popup, see this answer: https://stackoverflow.com/a/8172888/409820

Wait for message to send in window.onbeforeunload?

I'm messing around with Safari extensions, and I'd like my extension to respond to the user opening or closing tabs.
I have the extension injecting a script that runs when the new tab opens and notifies the global page that there's a new tab open. I want the script to also notify the global page when the tab closes. To do this, I'm having the injected script set the window.onbeforeunload function to call safari.self.tab.dispatchMessage. This works, but the problem is the tab closes and the Javascript gets killed before the message goes through. If, for example, I put an alert after the dispatchMessage to prevent the tab from closing until the user clicks OK, the message goes through fine, but this obviously isn't a very good user experience.
Is there a way to buy a little extra time right before the tab closes, or is there a better function to override for this or something?
The problem is that all messages save one (canLoad) are asynchronous. IMO, the canLoad is a bit of a hack itself, but I've used it effectively when I desperately need synchronous messaging for some reason. I asked an analogous question a while back that may help illustrate the canLoad solution/hack.

Categories