In my project, I want to re-open a new tab using ruby code. When user clicks at attachment link, then that pdf should be open in new tab of same window. I tried a lot but I am not getting the way to solve it. Please guide me.
I am not sure if this is possible using Ruby since it deals with the UI part. It is indeed very much possible using HTML and Jquery.
You could simply set the target attribute as blank in the hyperlink redirecting to the PDF and it will open the file in a new tab. Something similar to this :
<a href="http://www.mysite.com/files/xyz.pdf" target="_blank">
If you want to use JQuery for this, you can try something like this :
$(document).ready(function() {
$("a").click(function() {
link_host = this.href.split("/")[2];
document_host = document.location.href.split("/")[2];
if (link_host != document_host) {
window.open(this.href);
return false;
}
});
});
Related
My Share Dialog works well. But after user has pressed the Post to Facebook button. It directs user to a link. Probably the redirect_uri value.
The thing is the redirect_uri value cannot be left empty. I want the share dialog just disappears after posting. Is there a way to do this? I read through the Share Dialog documentation but cannot find a way to do this.
I found my solution :)
Here is the code for my share button:
Javascript:
function visitPage(){
testwindow = window.open("https://www.facebook.com/dialog/share?app_id=[myAppID]&display=popup&href=[linkA]&redirect_uri=[linkB]","html","width=200, height=100");
testwindow.moveTo(0,0);
}
HTML button:
<button onclick="visitPage()">Share</button>
And I created an HTML that closes itself immediately like this:
<!doctype html><html><head><script>
window.onload = function load() {
window.open('', '_self', '');
window.close();
};
</script></head><body></body></html>
name it selfClosing.html or something like that and then put it into link B. DONE! :)
I'm using dijit.dialog to show the popup dialog. How do I refresh the parent page on closing dijit.Dialog? Please advise. thanks
You need to add a listener to the hide event, and you need location.reload(). It will be a lot easier to answer your question if you post some code and list what you've tried already.
Here's a jsfiddle illustrating how to use location.reload() when a dijit/Dialog closes with Dojo 1.8.
The relevant code:
d.on('hide', function() {
console.log('closed');
location.reload();
});
You can use code as below, you just need to now your modal object's name.
var dialog = registry.byId("modalDialogObjectName");
var url = dialog.get("href");
dialog.set("href", url);
Using the Codeception testing framework and Selenium 2 module to test a website, I end up following a hyperlink that opens a new window with no name. As a result the switchToWindow() function will not work because it is trying to switch to the parent window (which I'm currently on). Without being able to switch to the new window I cannot perform any testing on it.
<a class="external" target="_blank" href="http://mylocalurl/the/page/im/opening">
View Live
</a>
Using both Chrome and Firefox debugging tools I can confirm the new window doesn't have a name, and I cannot give it one because I cannot edit the HTML page I am working on. Ideally I would have changed the HTML to use javascript onclick="window.open('http://mylocalurl/the/page/im/opening', 'myPopupWindow') however this is not possible in my case.
I've looked around on the Selenium forums without any clear method to tackle this problem, and Codeception doesn't appear to have much functionality around this.
After searching around on the Selenium forum and some helpful prods from #Mark Rowlands, I got it to work using raw Selenium.
// before codeception v2.1.1, just typehint on \Webdriver
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
Returning back to the parent window was easy because I could just use Codeception's switchToWindow method:
$I->switchToWindow();
Building on the accepted answer, in Codeception 2.2.9 I was able to add this code to the Acceptance Helper and it seems to work.
/**
* #throws \Codeception\Exception\ModuleException
*/
public function switchToNewWindow()
{
$webdriver = $this->getModule('WebDriver')->webDriver;
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
}
Then in the test class I can do this:
$I->click('#somelink');
$I->switchToNewWindow();
// Some assertions...
$I->switchToWindow(); // this switches back to the previous window
I had a heck of a time trying to figure out how to do this by just searching google, so I hope it helps someone else.
Try this,
String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator<String> windowIterator = browser.getWindowHandles();
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
}
make sure to return on parent window using,
browser.close(); // close the popup.
browser.switchTo().window(parentWindowHandle); // Switch back to parent window.
I hope will help you.
Using Codeception 2.2+ it looks like this:
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
});
Sorry for my very simple question, I'am new to HTML5 Builder.
I'm developing a simple database editing application (to add or remove some advertisments on site, only for system administrator), and I want to make it using HTML5 builder (I hope, it will be fast and simple).
On button click on main page ("Add record" button), I need to open another page with data fields (advinfo.php).
How can I do it?
Thanks.
You just need to redirect to the target page. How to do so will depend on the language you want to use.
If you want to use the JavaScript OnClick event of the button:
function Button1JSClick($sender, $params)
{
?>
//begin js
window.location = "advinfo.php";
//end
<?php
}
If you want to use the PHP OnClick event (the standard event):
function Button2Click($sender, $params)
{
header("Location: advinfo.php");
}
I am having real confusion with some flash banners I'm creating and making the button into a clickable object which opens a web page.
I have been using this code for a while below, which works...
on(release){
getURL("http://www.the-dude.co.uk", "_blank");
}
And I placed this code on actual button within the actions panel
However I have been told the code above is very old and that I should use action script like below...
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
So I've tried to get this method below to work but nothing happens when I click the button, and I get one error, this...
So in a nutshell I cannot get this newer code to work! Ahh
Can anyone please help me understand where I am going wrong?
I have tried placing the new code in the Scene 1 of my actions. No worky..
And I've also tried placing the code below, actually on my button within the actions panel...
this.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
Still not working.
My scene settings are alway this...
Any help would be great thanks.
You need to place the code below on the same timeline as the instance of the button (as you tried). And the instancename of the button must be "buttonInstance".
You can set the instance name in the properties panel when the button is selected.
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}