UIWebview Print option - javascript

I've created a container iOS app(objective c) which has only one webview. The webview is loaded with a website which is not owned by me. The website that i am accessing from webview has a print button. Tapping on it doesnt do anything. The same website when accessed via mobile browser works fine. I tried with several other websites with print button . It acts the same.
I wrote the following code for airprint. So whenever a native print button is clicked the following code is executed and it works fine.
But how can i execute this code when user clicks on print button on website ???
In other ways is there a way to detect if user clicks the print button on any website ??
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];

Related

Opening new tab with python Selenium (via javascript) suddenly stopped working

The Situation
I have this code below, which was working perfectly many many times the way it is, then all of a sudden it stopped working when it gets to the step of opening a new tab via javascript.
url = 'https://website'
opt = Options()
opt.add_argument('--start-maximized')
opt.add_argument("disable-infobars")
opt.add_experimental_option("detach", True)
service = Service(r'C:\Users\chromedriver_new.exe')
driver = webdriver.Chrome(options= opt,service = service)
login(url) ###function that opens the url and passes user/keyword - up to this part it's working perfectly
img_url = "https://website/" + url[30:55] + "/img.jpg" ##source of image I want to download
#The problem starts here, I've printed the img_url and I can open it fine in my navigator, but when I run the code it just stops here and never opens the new tab
#I've already tried changing the javascript by passing "+img_url+" directly
#I've also tried already to open a blank new tab and even this is not working
driver.execute_script('window.open(arguments[0],"_blank");',img_url) ###open link in new tab
time.sleep(2)
driver.switch_to.window(driver.window_handles[1]) ##change focus to new tab
time.sleep(2)
img_url_full = driver.find_element(By.XPATH,"/html/body/img").get_attribute("src") ##it gets the full path to the image, which includes a valid token that enables me to access (if I would try to downlaod the img_url directly it wouldn't work)
time.sleep(2)
urllib.request.urlretrieve(img_url_full,name) ##download image
Extra Information
I don't know if that has something to do with it, but usually my browser would always stay open unless I closed it manually (there is no close/quit on the code), but around the same time that the new tab stopped to work the browser started to close automatically right after the step of login - to avoid that I then had to add the
opt.add_experimental_option("detach", True)
(which is working).
The Question
Why is this happening and how could i debug this?

Speech synthesis keeps speaking on page load

In one of my PHP project I have integrated speech synthesis. On click of button I am calling a function for text to speech. Like,
var newUtterance = new SpeechSynthesisUtterance();
newUtterance.text = 'Test Message';
window.speechSynthesis.speak(newUtterance);
This works perfect. But when user refreshes the page it keeps speaking where I want to stop it on page load. I tried with,
On document ready function,
if (window.speechSynthesis.speaking) {
window.speechSynthesis.cancel();
}
and also like, On page load function,
var newUtterance = new SpeechSynthesisUtterance();
newUtterance.text = '';
window.speechSynthesis.speak(newUtterance);
But not working. Working on chrome browser. Thanks in advance.

closing browser within chrome page on test complete

So using TestComplete I'm essentially trying to open up a session on chrome, navigate to a web page, and then click a button on that page. after I'm finished I want to close that browser page. I'm having trouble closing the page though. Here is the code I have so far.
function ChromeTest
{
Browsers.Item(btChrome).Run(MyWebAdress);
var browser = Sys.Browser("chrome");
var page = Sys.Browser("chrome").Page(MyWebAdress);
var MyButton = page.ButtonLocation;
MyButton.click();
browser.BrowserWindow.Close(5000);
}
however, at the Close line I get an error that says "Unable to find the object BrowserWindow". Thanks in advance for any help you have.
Change BrowserWindow to BrowserWindow(0) (or whatever index you see in the Object Browser):
browser.BrowserWindow(0).Close(5000);
Or you can call Close() directly on the Chrome process:
browser.Close(5000);

safari window.open doesn't load contents of page until you click the tab of the window that loaded it

I've been trying to get this working correct for some time now...
within a function I have a response text from an ajax call called portinfotext. (it comes from a perl telnet script to run a sh ip int $interface on a cisco router.
It is then processed with portinfotextbr = portinfotext.replace(/\r?\n/g, '<br />');
To put these contents in a new window I have
var infowin = window.open('', '_blank', 'height=600,width=400,toolbar=0,location=0');
infowin.document.open();
infowin.document.write("<HTML><HEAD><TITLE>test</TITLE></HEAD><BODY><BR>"+portinfotextbr+"<BR><CENTER><input type='button' value='Close Window' onclick='window.close()'></CENTER></BODY></HTML>");
infowin.document.close();
This code works just fine on my mac using safari. If I use the iPad it opens a blank tab. If I click back quickly to the original tab the contents of the second tab will load. If I wait too long, the blank tab will not load when I click back.
To further complicate matters, if I don't put the var infowin declaration before the ajax call in the function I get the following error ONLY on the IPAD and IPHONE, not on the mac
TypeError : 'undefined' is not an object (evaluating infowin.document)
Any thoughts?

Javascript and CSS onclick Div Swap

I am new to both Javascript and designing for Facebook. I am using Shortstack to create custom tabs and have created a 3 panel sub-tab application using the service. In the 3rd panel, I have 19 div's holding information. By default, I use CSS to hide these DIVs (display:none;) and have a series of links at the top of the panel that change the visibility of each DIV onclick. Only the active onclick content is visible at any time.
The tab functions properly in Firefox, Chrome, and even Safari on the Mac, but fails in all browsers on the PC, and fails differently. In IE, immediately after the swap happens an error message pops up which mentions the publisher not allowing the action in an iFrame. In Firefox the tab just goes blank with no error message.
My script is below. As I stated, I am new to coding for Facebook and working with Javascript as I am a designer and not a programmer, but am eager to learn.
Thank you in advance for your thoughts and ideas.
function showhide(layer_ref) {
var thisDiv;
// check to see if any DIVs are currently showing
var divlist = ["div1","div2","div3","div4","div5","div6","div7","div8","div9","div10","div11","div12","div13","div14","div15","div16","div17","div18","div19"];
// loop through the list of DIVs in "divlist"
for (x = 0; x < divlist.length; x++) {
thisDiv = document.getElementById(divlist[x]);
// if the DIV is showing, hide it
if (thisDiv.style.display == "block") {
thisDiv.style.display = "none";
}
}
// show the appropriate DIV
thisDiv = document.getElementById(layer_ref);
thisDiv.style.display = "block";
}
If you try to change the things in iframe that could be a problem if the iframe is loaded from different domain. It is basically security rule - you don't want to allow rogue code to change/read/write things on the page other than it's own.
To answer your question better we need to know where is changing javascript is located and what it tries to change (are those two things loaded from the same domain or not).
The script itself looks ok to me.

Categories