How can pop up be made allowed when we use javascript in Qt??
-
function saveTextAsFile()
{
var textToWrite = document.getElementById("latbox").value+"\n"+document.getElementById("lngbox").value;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
//var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
//downloadLink.download = fileNameToSaveAs+".txt";
downloadLink.download = "values.txt";
downloadLink[removed] = "Download File";
if (window.webkitURL != null)
{
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else
{
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}here i had a button in javascript which when clicked pops up a download window asking for
saveas
oropen
. it is working outside Qt. but the pop up is blocked in Qt.
i tried all the available setting changes nothing worked :(QWebSettings *settings = ui->webView_2->settings();
settings->setAttribute(QWebSettings::JavascriptEnabled, true);
settings->setAttribute(QWebSettings::PluginsEnabled, true);
settings->setAttribute(QWebSettings::AutoLoadImages, true);
settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
settings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);
please help . how to make it work. -
What exactly do you mean? Maybe have a look at "QFile":http://qt-project.org/doc/qt-5.1/qtcore/qfile.html or "QSettings":http://qt-project.org/doc/qt-5.1/qtcore/qsettings.html , depending on what you want to achieve.
-
here you go:
@
QWebPage* page = myWebView->page();
page->setForwardUnsupportedContent(true); //<-- IMPORTANT!
connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(onDownload(const QNetworkRequest &)));
connect(page, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(onUnsupportedContent(QNetworkReply*)));...
//SLOT
void onDownload(const QNetworkRequest & request)
{
//this slot is called when the user right-clicks on an element and wants to save it, i'm not sure if it may be triggered also in your case
}//SLOT
void onUnsupportedContent(QNetworkReply* reply)
{
//this slot is called when the user should be prompted to download a file, so this is most probably the way to go for you
}
@ -
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Ground Overlays</title>
<link href="default.css" rel="stylesheet">
<div id="latlong">
<p>Latitude: <input size="20" type="text" id="latbox" name="lat" >Longitude: <input size="20" type="text" id="lngbox" name="lng" ></p>
</div>
<table>
<tr>
<td><button >Save Text to File</button></td>
</tr>
</table>
[removed][removed]
[removed]
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
function saveTextAsFile()
{
var textToWrite = document.getElementById("latbox").value+"\n"+document.getElementById("lngbox").value;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
//var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
//downloadLink.download = fileNameToSaveAs+".txt";
downloadLink.download = "values.txt";
downloadLink[removed] = "Download File";
if (window.webkitURL != null)
{
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
else
{
// Firefox requires the link to be added to the DOM
// before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
function initialize() {
var newark = new google.maps.LatLng(25,85);
var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(23.7407,82.4815),
new google.maps.LatLng(26.2593,87.5185));
var mapOptions = {
zoom: 5,
center: newark,
mapTypeId: google.maps.MapTypeId.SATELLITE
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var oldmap = new google.maps.GroundOverlay(
'file:///root/Documents/fwdjavascriptwritingvaluestoatextfile (copy)/wind10.jpg',
imageBounds);
oldmap.setMap(map);
var marker = new google.maps.Marker({
draggable: true,
position: newark,
map: map,
title: "Your location"
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("latbox").value = this.getPosition().lat();
document.getElementById("lngbox").value = this.getPosition().lng();
});
}
[removed]
</head>
<body >
<div id="map-canvas"></div>
</body>
</html>
this is my html code.in Qt i run this as
QString map_path = QDir::currentPath()+"/click.htm";
map_path = "file://"+map_path;
ui->webView_2->setUrl(QUrl(map_path));
ui->webView_2->update();normally if i run html file and click on save as button there appears a pop up asking to saveas or open with.
but in Qt webview no window is appeared even if i click on save as button.
please help.
-
first of all: use CODE TAGS!!!
second: did you read and tried anything of my previous post?!!