PDFTron - app.launchURL is not working with PDF Button in chrome - pdftron

We are showing pdf file in PDFTron webviewer(webviewer 5.2.9 legacy-ui) and PDF contains form fields and button, So on click on button we are extracting value from input and open url with argument. Below is the code snippet of button click.
Note : This works fine in Adobe and Foxit reader.
var p1 = this.getField("FirstName").value;
app.launchURL('http://localhost:8080/submit?FirstName='+p1,true);
When I click on button it is showing "webviewer-core.min.js:193 stub: app.launchURL called with: [object Arguments]" but it is not launching url.
Please see below snap for more details.

Currently the launch API is not implemented yet, however, you can update the launchURL function by yourself by using:
Annotations.Forms.EmbeddedJS.update(scope => {
scope.app.launchURL = function(url) {
window.open(url);
};
});
You can check more detail here https://www.pdftron.com/documentation/web/guides/forms/embedded-js/#customization

Related

YouTube and Fancybox 2

I am able to embed and view my YouTube videos in my website. The problem is: when MY videos finish, a YouTube screen appears with a number of OTHER PEOPLE'S videos as choices. I want the Fancybox pop-up to close when my video finishes so this doesn't happen. I have found a number of suggestions for closing the Fancybox pop-up when a YouTube video ends, but none of them work. I wonder if that's because they're written for Fancybox-1 and I'm using Fancybox-2. I've inserted the code below, but it doesn't trigger.
<script>
function onPlayerStateChange(event){
if (event.data===0){
$.fancybox.close();
}
}
</script>
I do this by adding ?rel=0 to the end of the URL which hides all related videos (more info on rel param here)
You can add ?rel=0 to each of your video URLs (manually), or have the fancybox beforeLoad function add it just before it opens: (example also sets autoplay to 1)
beforeLoad: function () {
var url = $(this.element).attr("href");
url += '?autoplay=1&rel=0';
this.href = url;
}
(Note that this code adds it to all videos and wont work if ? is already in the URL, so you may need to adjust the code to your page)

node-phantom handle hyperlink of iframe fail

Recently, i integrate node and phantomjs by phantomjs-node. I opened page that has iframe element, i can get the hyperlink element of iframe, but failed when i execute click on it.
Do you have a way? Anyone can help me?
example:
page.open(url);
...
page.evaluate(function(res){
var childDoc = $(window.frames["iframe"].document),
submit = childDoc.find("[id='btnSave']"),
cf = submit.text();//succeed return text
submit.click()//failed
return cf;
},function(res){
console.log("result="+res);//result=submit
spage.render("test.png");//no submit the form
ph.exit();
});
You can't execute stuff in an iframe. You can only read from it. You even created a new document from the iframe, which will only contain the textual representation of the iframe, but it is in no way linked to the original iframe.
You would need to use page.switchToFrame to switch to the frame to execute stuff on the frame without copying it first.
It looks like switchToFrame is not implemented in phantomjs-node. You could try node-phantom.
If the iframe is on the same domain you can try the following from here:
submit = $("iframe").contents().find("[id='btnSave']")
cf = submit.text();
submit.click()
If the iframe is not from the same domain, you will need to create the page with web security turned off:
phantom.create('--web-security=false', function(page){...});

How to programmatically open chrome extension popup.html

I have a created a desktop notification using google extension which works great:
icon = '';
var popup = window.webkitNotifications.createNotification(my notification');
icon, 'Awesome title', 'Click here to view more. ');
popup.show();
Is there a way to launch the actual google extension popup.html (as shown on the image below), when the user click on the the desktop notification?
Thanks.
Short answer is that you can't, but if you want to open the popup in a new tab instead, this is how you would do it:
Put this before you call show
popup.onclick = function() {
chrome.tabs.create({url : "popup.html"});
popup.cancel();
}
I wanted to add to the comment that Miscreant posted.
One approach that might work would be to setup a keyboard shortcut for
the pop up in the extension's manifest, then use an executable file to
artificially trigger that keyboard shortcut. See Native Messaging for
more info about how to communicate with an executable file from an
extension
This is how you set up a shortcut key that opens your extension.
...
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
}
}
Here's the API on 'commands'.

Chrome Extension that copies image URL on click

I'm brand new to making Chrome Extensions and have done the simple tutorials, but I'm having trouble finding what I need. I want the extension to allow a user to chose an image on a webpage, and then copy the URL for that image into the extension. Can anyone help me out? I'm sure if I see an example I'd get a better grasp on how extensions can interact with a page.
From what I understand of your question, I'd say you want to create a context menu item that shows up when you right-click an image. For example, in your background script, use:
chrome.contextMenus.create({
title: "Use URL of image somehow",
contexts:["image"],
onclick: function(info) {
handleImageURL(info.srcUrl);
}
});
function handleImageURL(url) {
// now do something with the URL string in the background page
}
This will add a context menu item that shows up on all pages, but only when you right-click on images. When the user selects it, the onclick handler of the menu item fires handleImageURL with the URL of the image as the argument. The URL can be processed in any way you like, e.g., saved in a localStorage list, sent to a server via Ajax, or passed in a message to a listening content script in the current tab.
EDIT with alternative:
You might want a content script that gets injected into every page. The script could bind an event listener to every image element at load time:
// in my_content_script.js...
var imgs = document.getElementsByTagName("img");
for(var i = 0, i < imgs.length; ++i) {
imgs[i].addEventListener("click", function() {
alert(this.src);
// do things with the image URL, this.src
});
}
To inject it into all subdomains of example.com, your manifest would include:
...
"content_scripts": {
"matches":["*://*.example.com/*"],
"scripts":["my_content_script.js"]
},
...
Note that this pure-JS solution doesn't attach listeners to images dynamically added after load time. To do that in your content script with jQuery, use:
$(document).on("click", " img", function() {
alert(this.src);
});
And add your jQuery file name to the scripts array in your manifest, next to my_content_script.js.
Based on this Google Chrome Extension sample:
var images = [].slice.apply(document.getElementsByTagName('img'));
var imageURLs = images.map(function(image) {
return image.src;
});
chrome.extension.sendRequest(images);
For a more detailed example (e.g. how to handle the request), you can check out this extension I wrote called Image Downloader

Phantom.js fill fields,click submit, and now stuck at accessing the next page

I've start with phantom.js (btw I'm in love). I'm trying to make the headless browser go to my php admin panel, log in with a username and password, and from the page that it redirects to after log in i want to get some text from a div tag.
So far I manage to successfully fill the fields, create a click event, and even find the access to the DOM part of the div tag and get the inner.Text.
The only missing part for me is what to do when phantom.js clicks on a button (the log in button in this case) which will log me in and change the page content. I can't find how to handle after .click(); event.
This is the code I made so far (by the way its a good way to start with...)
var page = new WebPage();
page.open("the url comes here",
function(status){
if(status != "success"){console.log('fail loading the page');}
page.evaluate(function(){
var arr = document.getElementsByName("formname");
arr[0].elements["username"].value="username here";
arr[0].elements["password"].value="password here";
arr[0].elements["submit"].click();
return;
}
phantom.exit()
});
The code i want run on the page that comes after it is
console.log(window.frames[1].document.getElementById('status').innerHTML)
So the only question remaining is how to handle the redirect and launch the script on the other page.
Thanks,
You need to setup a new callback for the page load:
page.onLoadFinished = function(status){
console.log(window.frames[1].document.getElementById('status').innerHTML)
}
this should come right before triggering .click().

Resources